/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights
 * reserved. <a>http://www.cqcis.com</a>
 */
package com.cqcis.uip.base.framework.service;

import javax.xml.namespace.QName;

import org.apache.axis.ConfigurationException;
import org.apache.axis.Handler;
import org.apache.axis.SimpleTargetedChain;
import org.apache.axis.configuration.FileProvider;

import com.cqcis.uip.base.framework.core.RegisteredService;
import com.cqcis.uip.base.framework.service.impl.HTTPSenderAdaptor;

/**
 * FILE
 * 
 * @author huangmy
 * @date 2008-11-3
 */
public class FileProviderAdaptor extends FileProvider {
	protected static final String CLIENT_CONFIG_FILE = "client-config.wsdd";
	private SimpleTargetedChain httpTc; // TC
	private RegisteredService currentRS;
		
	public FileProviderAdaptor(String filename, RegisteredService currentRS) {
		super(filename);		
		this.currentRS = currentRS;
	}
	
	public FileProviderAdaptor(RegisteredService currentRS) {
		super(CLIENT_CONFIG_FILE);	
		this.currentRS = currentRS;
	}
	
	@Override
	public synchronized Handler getTransport(QName qname) throws ConfigurationException {
		String name = qname.toString();
		if ("http".equalsIgnoreCase(name)) {
		    if (this.httpTc != null) {
		    	return this.httpTc;
		    }
		    		    	    
		    this.httpTc = new SimpleTargetedChain(new HTTPSenderAdaptor(this.currentRS));
		    
			return this.httpTc;
		}
		return super.getTransport(qname);
	}
}
